package com.sakura.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sakura.commonutils.R;
import com.sakura.eduservice.entity.EduCourse;
import com.sakura.eduservice.entity.EduTeacher;
import com.sakura.eduservice.service.EduCourseService;
import com.sakura.eduservice.service.EduTeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {
    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    @ApiOperation("查询前8条热门课程，查询前4条名师")
    @GetMapping("index")
    public R index(){
        //查询前8条热门课程
        List<EduCourse> courseList = courseService.list(new QueryWrapper<EduCourse>()
                .orderByDesc("id").last("limit 8"));
        //查询前4条名师
        List<EduTeacher> teacherList = teacherService.list(new QueryWrapper<EduTeacher>()
                .orderByDesc("id").last("limit 4"));
        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
}
